function qiniuUploadFile(file, key, onProgress, onError, onComplete) {
    var putExtra = {
        params: {} //自定义参数，服务器端生成Token时auth.uploadToken的最后一个参数需要指定false
    };
    var config = {
        useCdnDomain: false, //使用sdn加速域名
        region: qiniu.region.z2, //华南服务器
        checkByMD5: true //开启分片MD5校验，能确保断点续传的可靠性，但会更耗时
    };
    var observer = {
        next(progress) {
            if (onProgress) {
                onProgress(Math.round(progress.total.percent));
            }
        },
        error(err) {
            if (onError) {
                onError('上传七牛失败');
            }
        },
        complete(complete) {
            console.log('complete: ' + JSON.stringify(complete))
            if (onComplete) {
                onComplete(complete.key);
            }
        }
    }
    $.ajax({
        url: contextPath + '/admin/qiniu/getUploadToken?overrideKey=' + key,
        success: function (res) {
            var token = res;
            var observable = qiniu.upload(file, key, token, putExtra, config);
            observable.subscribe(observer);
        },
        error: function (err) {
            console.log('获取uploadToken失败：' + JSON.stringify(err));
        }
    });

}

function qiniuDelFile(fileKey, callback) {
    console.log('开始删除：' + fileKey)
    $.ajax({
        url: contextPath + '/admin/qiniu/delFile',
        method: 'post',
        data: {
            fileKey: fileKey
        },
        success: function (res) {
            if (res.code == 0) {
                console.log('已删除上传成功的文件');
            } else {
                console.log('删除上传的文件失败');
            }
            if (callback) {
                callback();
            }
        },
        error: function (err) {
            console.log('删除上传的文件失败：' + JSON.stringify(err));
            if (callback) {
                callback();
            }
        }
    });
}